<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/html/axios.min.js"></script>
    <script>
        function $(id) {
         return document.getElementById(id)
        }
        function getQuery(variable)
        {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i=0;i<vars.length;i++) {
                var pair = vars[i].split("=");
                if(pair[0] == variable){return pair[1];}
            }
            return(false);
        }
        function getMain(pageNum,chanelId) {
            axios.get("/main/findByItem",{
                params:{
                    pageNum:pageNum,
                    chanelId:getQuery("id"),
                    name:$("title").value,
                    author:$("author").value,
                    startDDate:$("startDate").value,
                    endDate:$("endDate").value
                }
            }).then(resp =>{
                var obj = resp.data.list;
                var str = ""
                obj.forEach(e =>{
                    str +=`<tr><td>${e.title}</td><td>${e.author}</td><td>${e.postNumber}</td><td>${e.postDate}</td></tr>`
                    $("mainDate").innerHTML = str
                });
                let pageN ="";
                for(let i=1;i<=resp.data.pages;i++){
                    pageN +=`<a style="margin-left: 10px" href="javascript:findByItem(${i})">${i}</a>`
                    $("pageDiv").innerHTML =pageN;
                }
            });
        }
        function postTopic(channelId) {
            axios.get("/main/add",{
                params:{
                    channelId:getQuery("id"),
                    title:$("title").value,
                    content:$("content").value,
                }
            }).then(resp =>{
                if(resp.data == "ok"){
                   getMain()
                }
            });
        }
        function returnM() {
           location.href="/html/index.html"
        }

    </script>
</head>
<body>
      标题:<input type="text" id="title"><br>
      内容:<input type="text" id="content" style="width: 100px;height: 100px"><br>
      <input type="button" value="发表" onclick="postTopic()">
      <input type="button" value="返回" onclick="returnM()"><br>
</body>
</html>